home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC_Samples / collect / mainfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  4.5 KB  |  174 lines

  1. // mainfrm.cpp : implementation of the CMainFrame class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1999 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "collect.h"
  15.  
  16. #include "mainfrm.h"
  17.  
  18. #include "colledoc.h"
  19. #include "strlstvw.h"
  20. #include "typlstvw.h"
  21. #include "intlstvw.h"
  22. #include "dwarryvw.h"
  23. #include "typaryvw.h"
  24. #include "ptarryvw.h"
  25. #include "mapssvw.h"
  26. #include "typtrmap.h"
  27. #include "mapdwvw.h"
  28.  
  29. #ifdef _DEBUG
  30. #undef THIS_FILE
  31. static char BASED_CODE THIS_FILE[] = __FILE__;
  32. #endif
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CMainFrame
  36.  
  37. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  38.  
  39. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  40.     ON_COMMAND_RANGE(ID_STRINGLIST, ID_MAP, OnExample)
  41.     ON_UPDATE_COMMAND_UI_RANGE(ID_STRINGLIST, ID_MAP, OnUpdateExampleUI)
  42.     //{{AFX_MSG_MAP(CMainFrame)
  43.     ON_WM_CREATE()
  44.     //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CMainFrame construction/destruction
  49.  
  50. CMainFrame::CMainFrame()
  51. {
  52.     m_nCurrentExample = ID_STRINGLIST;
  53. }
  54.  
  55. CMainFrame::~CMainFrame()
  56. {
  57. }
  58.  
  59. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  60. {
  61.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  62.         return -1;
  63.  
  64. #if (_WIN32_WCE > 200)
  65.     if(!m_wndCommandBar.Create(this) ||
  66.        !m_wndCommandBar.InsertMenuBar(IDR_MAINFRAME) ||
  67.        !m_wndCommandBar.AddAdornments())
  68.     {
  69.         TRACE0("Failed to create CommandBar\n");
  70.         return -1;      // fail to create
  71.     }
  72. #else // MFC for Windows CE 1.0 and 2.0
  73.     if(!AddAdornments(0))
  74.     {
  75.         TRACE0("Failed to create CommandBar\n");
  76.         return -1;      // fail to create
  77.     }
  78. #endif
  79.  
  80.     return 0;
  81. }
  82.  
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CMainFrame diagnostics
  85.  
  86. #ifdef _DEBUG
  87. void CMainFrame::AssertValid() const
  88. {
  89.     CFrameWnd::AssertValid();
  90. }
  91.  
  92. void CMainFrame::Dump(CDumpContext& dc) const
  93. {
  94.     CFrameWnd::Dump(dc);
  95. }
  96.  
  97. #endif //_DEBUG
  98.  
  99. /////////////////////////////////////////////////////////////////////////////
  100. // CMainFrame message handlers
  101.  
  102. void CMainFrame::OnExample(UINT nCmdID)
  103. {
  104.     if (nCmdID == m_nCurrentExample)
  105.         return;  // already selected
  106.  
  107.     // Set the child window ID of the active view to AFX_IDW_PANE_FIRST.
  108.     // This is necessary so that CFrameWnd::RecalcLayout will allocate
  109.     // this "first pane" to that portion of the frame window's client
  110.     // area not allocated to control bars.  Set the child ID of
  111.     // the previously active view to some other ID; we will use the
  112.     // command ID as the child ID.
  113.     CView* pOldActiveView = GetActiveView();
  114.         ::SetWindowLong(pOldActiveView->m_hWnd, GWL_ID, m_nCurrentExample);
  115.  
  116.     CRuntimeClass* pNewViewClass;
  117.     switch (nCmdID)
  118.     {
  119.         case ID_STRINGLIST:
  120.             pNewViewClass = RUNTIME_CLASS(CStringListView);
  121.             break;
  122.         case ID_TYPEDLIST:
  123.             pNewViewClass = RUNTIME_CLASS(CTypedPtrListView);
  124.             break;
  125.         case ID_INTLIST:
  126.             pNewViewClass = RUNTIME_CLASS(CIntListView);
  127.             break;
  128.         case ID_DWORDARRAY:
  129.             pNewViewClass = RUNTIME_CLASS(CDWordArrayView);
  130.             break;
  131.         case ID_TYPEDPTRARRAY:
  132.             pNewViewClass = RUNTIME_CLASS(CTypedPtrArrayView);
  133.             break;
  134.         case ID_POINTARRAY:
  135.             pNewViewClass = RUNTIME_CLASS(CPointArrayView);
  136.             break;
  137.         case ID_MAPSTRINGTOSTRING:
  138.             pNewViewClass = RUNTIME_CLASS(CMapStringToStringView);
  139.             break;
  140.         case ID_TYPEDPTRMAP:
  141.             pNewViewClass = RUNTIME_CLASS(CTypedPtrMapView);
  142.             break;
  143.         case ID_MAPDWORDTOMYSTRUCT:
  144.             pNewViewClass = RUNTIME_CLASS(CMapDWordToMyStructView);
  145.             break;
  146.         default:
  147.             ASSERT(0);
  148.             return;
  149.     }
  150.  
  151.     // create the new view
  152.     CCreateContext context;
  153.     context.m_pNewViewClass = pNewViewClass;
  154.     context.m_pCurrentDoc = GetActiveDocument();
  155.     CView* pNewView = STATIC_DOWNCAST(CView, CreateView(&context));
  156.     if (pNewView != NULL)
  157.     {
  158.         // the new view is there, but invisible and not active...
  159.         pNewView->ShowWindow(SW_SHOW);
  160.         pNewView->OnInitialUpdate();
  161.         SetActiveView(pNewView);
  162.         RecalcLayout();
  163.         m_nCurrentExample = nCmdID;
  164.  
  165.         // finally destroy the old view...
  166.         pOldActiveView->DestroyWindow();
  167.     }
  168. }
  169.  
  170. void CMainFrame::OnUpdateExampleUI(CCmdUI* pCmdUI)
  171. {
  172.     pCmdUI->SetCheck(pCmdUI->m_nID == m_nCurrentExample);
  173. }
  174.